var t = getApp();

Page({
    data: {
        list: [],
        SearchValue: "",
        choose_index: 1,
        order_type: 0,
        search_type: 0,
        cate_id: "",
        sort: {
            up: 0,
            down: 0
        },
        current_page: 1,
        last_page: 1
    },
    getMoreData: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var t = {
                page: Number(this.data.current_page) + 1,
                order_type: this.data.order_type,
                search_type: this.data.search_type
            };
            this.data.cate_id && (t.cate_id = this.data.cate_id), this.data.SearchValue && (t.title = this.data.SearchValue), 
            this.getData(t);
        }
    },
    onSearch: function(t) {
        var a = t.detail;
        this.setData({
            SearchValue: a
        }), this.getData({
            page: 1,
            title: a,
            search_type: this.data.search_type,
            order_type: this.data.order_type
        });
    },
    choose: function(t) {
        var a = t.currentTarget.dataset.index;
        this.setData({
            choose_index: a
        }), 1 !== a ? 0 == this.data.sort.up && 0 == this.data.sort.down ? this.setData({
            "sort.up": 1,
            "sort.down": 0
        }) : 1 == this.data.sort.up && 0 == this.data.sort.down ? this.setData({
            "sort.up": 0,
            "sort.down": 1
        }) : 0 == this.data.sort.up && 1 == this.data.sort.down && this.setData({
            "sort.up": 1,
            "sort.down": 0
        }) : 1 == a && this.setData({
            "sort.up": 0,
            "sort.down": 0
        }), 1 == this.data.sort.down ? this.setData({
            order_type: 1
        }) : this.setData({
            order_type: 0
        });
        var e = a - 1;
        this.setData({
            search_type: e
        }), this.getData({
            page: 1,
            order_type: this.data.order_type,
            search_type: e,
            title: this.data.SearchValue
        });
    },
    onLoad: function(t) {
        console.log(t);
        var a = {
            page: 1,
            title: this.data.SearchValue,
            search_type: this.data.search_type,
            order_type: this.data.order_type
        };
        t.cate_id && (a.cate_id = t.cate_id, this.setData({
            cate_id: t.cate_id
        })), t.title && (a.title = t.title, this.setData({
            SearchValue: t.title
        })), this.getData(a);
    },
    getData: function(a) {
        var e = this;
        t._getNetWork({
            url: t.getNetAddresss("plugin.tiktok-cps.api.goods.good-list"),
            data: a,
            success: function(s) {
                var r = s.data;
                if (0 == r.result) return t.tips(r.msg);
                if (1 == a.page) e.setData({
                    list: r.data.products
                }); else if (a.page > 1) {
                    var i = e.data.list.concat(r.data.products);
                    e.setData({
                        list: i
                    });
                }
                e.setData({
                    current_page: r.data.current_page,
                    last_page: r.data.last_page
                });
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.getMoreData();
    },
    onShareAppMessage: function() {}
});